package cn.cdutetc.library.entity.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 借阅状态枚举
 */
@Getter
@AllArgsConstructor
public enum BorrowStatusEnum {

    BORROWED(1, "借出"),
    RETURNED(2, "已还"),
    OVERDUE(3, "逾期"),
    LOST(4, "丢失");

    private final Integer code;
    private final String desc;

    /**
     * 根据code获取枚举
     * @param code 状态码
     * @return 枚举
     */
    public static BorrowStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (BorrowStatusEnum status : BorrowStatusEnum.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}